package com.perfectoMobile.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PmProperteis{
	
	private static Map<String,String> pm =new HashMap<String, String>();
	private  Properties p = null;
	File f = null;
	
	
	
	public PmProperteis(String filePath){
		try{
		f = new File(filePath);

		if (!f.exists())
			throw new FileNotFoundException();

		else {

			p = new Properties();
			p.load(new FileReader(f));

			 Set set = p.keySet();

			for(Object obj : set) {
				
				if (ePmProperties.contain((String)obj)) {
					pm.put((String)obj, p.getProperty((String)obj));
				}

			}

		}
		}catch(FileNotFoundException e){System.err.println(e.getMessage());}
		catch(IOException e){System.err.println(e.getMessage());}		

	}
	
	
	public static String  getProperty(ePmProperties key){
	
		return pm.get(key.toString());
		
	}
	
	public  Boolean setProperty(String key, String value) throws IOException{
	try{
		p.setProperty(key, value);
		p.store(new FileWriter(f), "");
		pm.put(key, value);
		return true;
	}
	catch(Exception e){
		return false;
	}
		
		
	}

	

	
	public enum ePmProperties{
		DEVICES,BROWSER;
	
		public static boolean contain (String p){
			for (ePmProperties prop : ePmProperties.values()){
				if(prop.toString().equals(p)){
					return true;
				}
			}
			return false;
		}
		
		
				
	}
		

}
